package com.example.hotel_demo.controller;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;



@Controller
@ComponentScan
public class LoginController {

    @RequestMapping("/logout")
    public String getoutlogin( HttpSession session){
        session.setAttribute("username",null);
        return "/login";
    }


    @RequestMapping("/loginSuccess")
    public String loginSuccess(HttpSession session) {
        int role = (int) session.getAttribute("loginRole");
        if (role == 1) {
            //进入用户页面
            return "user";
        } else {
            return "/admin/admin";
        }
    }

    @RequestMapping("/login-go")
    @ResponseBody
    public String nologin() {
        return "<script type='text/javascript'>alert('您未进行登录,请进行登录');window.location='/login'</script>";
    }



    /**
     * 这种RESTful方式不适用于登录，此方式将各种资源对应一个url，提交表单不方便
     @RequestMapping(value = "/{username}/{password}",method = RequestMethod.GET)
     public User selectUser(@PathVariable("username")String username, @PathVariable("password")String password){
     System.out.println("1");
     System.out.println("username ="+username + ",password ="+ password);
     User user = loginService.loginCheck(username,password);
     System.out.println(user);
     return user;
     }
     */


}
